package com.kkwrite.regimen.common.entity.dto.login;

import java.io.Serializable;
import java.util.regex.Pattern;

/**
 * Created by lisha on 2018/8/16 13:34.
 *
 * @author lisha
 */
public class ShopLoginInDTO implements Serializable {
    private static final long serialVersionUID = -2022569491959078862L;
    private static final Pattern PATTERN = Pattern.compile("^1\\d{10}$");

    private String username;
    private String phoneNum;
    private String password;
    private String code;

    public boolean isInvalid() {
        if (isBlank(username) && isBlank(phoneNum)) {
            return true;
        }
        if (isBlank(password)) {
            return true;
        }
        return !isBlank(phoneNum) && !PATTERN.matcher(phoneNum).matches();
    }

    private boolean isBlank(String string) {
        return string == null || string.trim().isEmpty();
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPhoneNum() {
        return phoneNum;
    }

    public void setPhoneNum(String phoneNum) {
        this.phoneNum = phoneNum;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @Override
    public String toString() {
        return "ShopLoginInDTO{" +
                "username='" + username + '\'' +
                ", phoneNum='" + phoneNum + '\'' +
                ", password='" + password + '\'' +
                ", code='" + code + '\'' +
                '}';
    }
}
